package com.lhg;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * <p>
 *     TODO
 * </p>
 *
 * @author liuhuagui
 * @since 2022/10/31
 */
public class NewGenerator {
    public static void main(String[] args) {


        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/hmdb?useSSL=false&serverTimezone=UTC", "root", "123456")
                .globalConfig(builder -> {
                    builder.author("baomidou") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir("D://code/test"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.lhg") // 设置父包名
                            // 模块名
                            .moduleName("xxxxx")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .xml("/mapper/xml")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D://code/test")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    // 设置需要生成的表名
                    builder.addInclude("tb_blog")
                            // 设置过滤表前缀
                            .addTablePrefix("tb_", "c_");
                    // --- 实体策略 ---
                    builder.entityBuilder()
                            .enableFileOverride()
                            .enableLombok().enableChainModel();

                    // --- 服务类 ---
                    builder.serviceBuilder()
                            .enableFileOverride()
                            .formatServiceFileName("I%sService")
                            .formatServiceImplFileName("%sServiceImpl");

                    // --- 控制层 ---
                    builder.controllerBuilder().enableFileOverride();

                    // --- mapper ---
                    builder.mapperBuilder().enableFileOverride();
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
